﻿/**
 * Created by lizeshuai on 2017/3/27.
 */
window.onload= function () {
	var errorCount = 0;
    //分页索引
    var iIndex = 0;
    //每页展示10个
    var iPage = 2;
    var pageStart = 0,
        pageEnd = 0;
    //分类
    //列表数据读取
    // dropload
    $('#wrap').dropload({
        scrollArea: window,
		distance : -1,
        loadDownFn: function(me) {
            //var result = '';
            iIndex++;
            $.ajax({
                type: 'GET',
                url: '/listData',
                dataType: 'jsonp',
                data : {
                	"type" : articleType,
                	"pageNo" : iIndex
                },
                success: function(data) {
                    console.log(data);
					var result = "";
                    if (data.code == 200&&data.data.length>0) {
                    	
						for(var i in data.data){
							result += '<li >';
								result += '<a href="/article/'+ data.data[i].id +'.html" >';
									result += '<img src="'+ img_prefix_oss_plt + data.data[i].imgPath +'">';
									result += '<p class="p1">'+ data.data[i].title +'</p>';
									result += '<p class="p2">';
										result += '<span>日期：</span>';
										result += '<span>'+ data.data[i].createTime +'</span>';
										result += '<span class="article-list-mt">浏览量</span>';
										result += '<span>'+ data.data[i].hits +'</span>';
									result += '</p>';
								result += '</a>';
							result += '</li>';
							
						}
                    }else{
                        // 锁定
                        me.lock();
                        // 无数据
                        me.noData();
                    }
                    $('#article-content').append(result);
                    // 每次数据加载完，必须重置
                    me.resetload();
                },
                error: function(xhr, type) {
                    //alert('Ajax error!');
                    // 即使加载出错，也得重置
                	errorCount++;
                	if(errorCount < 3){
                		me.resetload();
                	}
                	me.noData();
                }
            });
        }
    });
    $(document).on("scroll", function () {
        //console.log($(".header-content").height());
        if(($(".header").height()-$("body").scrollTop())<=0){
            $(".main-head").css({
                "top":0,
                "box-shadow":"0px 0px 8px 2px rgba(0, 0, 0, 0.3)"
            })
        }else{
            $(".main-head").css({
                "top":$(".header").height()-$("body").scrollTop(),
                "box-shadow":"none"
            })
        }
        if($("body").scrollTop()==0){
            $(".main-head").css({
                "top":$(".header").height(),
                "box-shadow":"none"
            })
        }
    })
    $(".main-head ul li").on("click", function () {
        $(".main-head ul li").removeClass("active");
        $(this).addClass("active");
    })
}


